package cn.tuling.org.service.impl;

import cn.tuling.basic.util.PageList;
import cn.tuling.org.domain.Photo;
import cn.tuling.org.mapper.PhotoMapper;
import cn.tuling.org.query.PhotoQuery;
import cn.tuling.org.service.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class PhotoServiceImpl implements PhotoService {
    @Autowired
    private PhotoMapper photoMapper;
    @Transactional
    @Override
    public void addPhoto(Photo photo) {
        photoMapper.addPhoto(photo);
    }
    @Transactional
    @Override
    public void delePhotoById(Long id) {
        photoMapper.delePhotoById(id);
    }
    @Transactional
    @Override
    public void updatePhoo(Photo photo) {
        photoMapper.updatePhoo(photo);
    }

    @Override
    public List<Photo> findAllPhoto() {
        return photoMapper.findAllPhoto();
    }

    @Override
    public PageList<Photo> findPagingPhoto(PhotoQuery photoQuery) {
        Integer photoNumber = photoMapper.findPhotoNumber(photoQuery);
        if (photoNumber == 0 || photoNumber == null) {
            return  new PageList<Photo>();
        }
        List<Photo> photoList = photoMapper.findPagingPhoto(photoQuery);
        System.out.println(photoList);
        return new PageList<>(photoNumber,photoList);
    }
}
